#include "orbitalcamera.h"
#include <gl/GLU.h>

const float g_maxAngle = 60*3.14f/180;

OrbitalCamera::OrbitalCamera( const Vec3& eye, const Vec3& target )
	: m_fYangle(0.0f)
	, m_fXAngle(0.0f)
	, m_eye(eye)
	, m_target(target)
{

}

OrbitalCamera::OrbitalCamera()
	: m_fYangle(0.0f)
	, m_fXAngle(0.0f)
{

}

void OrbitalCamera::apply()
{
	gluLookAt(m_eye.x, m_eye.y, m_eye.z, 
		m_target.x, m_target.y, m_target.z, 0.0f, 1.0f, 0.0f);
}

void OrbitalCamera::rotate( const QPointF& angleOffset )
{
	Vec3 camVec = vecUnitVector(m_target - m_eye);
	Vec3 defaultUpVec(0, 1, 0);
	Vec3 rightVec = vecUnitVector(vecCrossProduct(camVec, defaultUpVec));
	Vec3 upVec = vecUnitVector(vecCrossProduct(rightVec, camVec));

	m_eye += rightVec*angleOffset.x()*(-10.0f);
	m_eye += upVec*angleOffset.y()*10.0f;
}

void OrbitalCamera::pan( const QPointF& offset )
{

}

void OrbitalCamera::zoom( float amount )
{
	Vec3 camVec = vecUnitVector(m_target - m_eye);
	m_eye += camVec*amount;
}
